package laf;

import java.io.IOException;
import java.util.ResourceBundle;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import laf.time.TimeManager;
import laf.time.Timer;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

public class ConfigParser {
	private final static String E_TIME = "time";
	private final static String E_ENVIROMENT = "enviroment";
	private final static String E_LANGUAGE = "language";
	
	public void parse() throws ParserConfigurationException, SAXException, IOException {
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		factory.setValidating(true);
		factory.setIgnoringElementContentWhitespace(true);
		DocumentBuilder builder = factory.newDocumentBuilder();
		Document doc = builder.parse("D:\\Documents\\Projects\\JADE\\LAF\\config\\test.conf.xml");
		
		processTime(doc.getElementsByTagName(E_TIME).item(0));
		processEnviroment(doc.getElementsByTagName(E_ENVIROMENT).item(0));
		processLanguage(doc.getElementsByTagName(E_LANGUAGE).item(0));
		
		
		

		System.out.println();
	}

	private void processLanguage(Node item) {
		// TODO Auto-generated method stub
		
	}

	private void processEnviroment(Node item) {
		
	}

	private void processTime(Node item) {
		Node elem = item.getFirstChild();
		if (elem != null) {
			TimeManager timer = TimeManager.getInstance();
			Node attr;
			String value;
			attr = elem.getAttributes().getNamedItem("tickDuration");
			if (attr != null) {
				value = attr.getNodeValue();
				long tickDuration = Long.parseLong(value);	
				timer.setTickDuration(tickDuration);
				timer.start();
			}
		}
	}

}
